using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FrontSight : MonoBehaviour
{
    private Vector3 inputMovement;
    public float speed = 10f;
    public GameObject frontSight;
    
    public float maxOffset = 180f;
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (frontSight == null)
        {
            return;
        }
        // Vector3 inputVector = Vector3.ClampMagnitude(inputMovement, speed);
        
        //规定移动距离只能在指定直径范围内
        // float distance = Vector3.Distance(frontSight.transform.position, inputMovement);
        // Debug.Log(distance);
        // if (distance > speed)
        // {
        //     inputMovement = Vector3.ClampMagnitude(inputMovement, speed);
        // }
        // else
        // {
        //     inputMovement = inputMovement.normalized * distance;
        // }

        // Debug.Log(inputMovement.magnitude);
        //
        // if (inputMovement.magnitude > maxOffset)
        // {
        //     frontSight.transform.position = inputMovement.normalized * maxOffset;
        //     
        // }
        // else
        // {
        //     
        // }
        
        Vector3 inputVector = Vector3.ClampMagnitude(inputMovement, speed);
        inputVector = inputVector.normalized;
        frontSight.transform.position += inputVector * Time.deltaTime * speed;
        

        // if (frontSight.transform.position.x < 5)
        // {
        //     frontSight.transform.position += inputVector * Time.deltaTime * speed;
        // }
        
    }
    
    //获取更新位置
    public void updatePos(Vector3 pos)
    {
        Debug.Log("移动");
        inputMovement = pos;
    }

    
}
